
from imposm.parser import OSMParser
import math
import sys
class roads(object):
   road_node=[]
   smal_lat=0
   smal_lon=0
   comp=100
   id1=0
   def ways(self,ways):
       #print "w" 
       for osm_id,tags,ref in ways:
		if 'highway' in tags:
                           for i in ref:
                             self.road_node.append(i)
   def coords(self,coords):
       #print "c"
       #self.road_node.sort()
       self.road_node=list(set(self.road_node))
       file1=open("road.b","a")
       for osm_id,lon,lat in coords:
		for i in self.road_node:
                     if i == osm_id:
                           lat2,lon2=lat,lon
                           lat1,lon1=12.9617224,77.6027042
                           dlat = lat2 - lat1
                           dlon = lon2 - lon1
                           dist2 = dlat * dlat + dlon * dlon
                           dist=math.sqrt(dist2)*100
                           print dist
                           if dist<0.01:
                               self.stop1(lat,lon,osm_id)
                               sys.exit()
                           break
     
   def stop1(self,lat,lon,osmid):
       print lat,lon,osmid
road_scraper = roads()

p = OSMParser(concurrency=1, ways_callback=road_scraper.ways)
p.parse('map.osm')
t = OSMParser(concurrency=1, coords_callback=road_scraper.coords)
t.parse('map.osm')


#print road_scraper.smal_lat,road_scraper.smal_lon,road_scraper.id
